
let item = {
	getCurrentDateStr: function(now) {
		if (!now) {
			now = new Date();
		}
	    const y = now.getFullYear().toString();
	    const m = (now.getMonth() + 1).toString().padStart(2, '0');
		const d = now.getDate().toString().padStart(2, '0');
	    return `${y}-${m}-${d}`;
	},
	getCurrentTime: function() {
	    const now = new Date();
	    const hours = now.getHours().toString().padStart(2, '0');
	    const minutes = now.getMinutes().toString().padStart(2, '0');
	    return `${hours}:${minutes}`;
	},
	getTimeDifference: function(st, et) {
	    // 将时间字符串转换为分钟数
	    function timeToMinutes(timeStr) {
	        const [hours, minutes] = timeStr.split(':').map(Number);
	        return hours * 60 + minutes;
	    }
	    
	    const stMinutes = timeToMinutes(st);
	    const etMinutes = timeToMinutes(et);
	    
	    return etMinutes - stMinutes;
	},
	insertIntervalObjects: function(arr) {
	    const result = [];
	    let currentTime = item.getCurrentTime();
	    // 1. 处理空数组的情况
	    if (arr.length === 0) {
	        // 如果数组为空，添加一个默认对象
	        result.push({ st: currentTime, et: "23:59" });
	        return result;
	    }
	    
	    if (arr[0].st > currentTime) {
			// 2. 向数组前面添加对象
			const firstStMinus5 = item.addMinutes(arr[0].st, -5);
			result.push({
			    st: currentTime,
			    et: firstStMinus5
			});
		}
	    
	    // 3. 添加第一个原始对象
	    result.push({...arr[0]});
	    
	    // 4. 在对象之间插入间隔对象
	    for (let i = 0; i < arr.length - 1; i++) {
	        const current = arr[i];
	        const next = arr[i + 1];
	        
	        // 计算插入对象的开始时间和结束时间
	        const insertSt = item.addMinutes(current.et, 5);
	        const insertEt = item.addMinutes(next.st, -5);
	        
	        // 只有当插入时间有效时才插入
	        if (item.timeToMinutes(insertSt) < item.timeToMinutes(insertEt)) {
	            result.push({
	                st: insertSt,
	                et: insertEt
	            });
	        }
	        
	        // 添加下一个原始对象
	        result.push({...next});
	    }
	    
	    // 5. 向数组后面添加对象
	    const lastEtPlus5 = item.addMinutes(arr[arr.length - 1].et, 5);
	    result.push({
	        st: lastEtPlus5,
	        et: "23:59"
	    });
	    
	    return result;
	},
	
	
	timeToMinutes: function(timeStr) {
	    const [hours, minutes] = timeStr.split(':').map(Number);
	    return hours * 60 + minutes;
	},
	
	// 辅助函数：将分钟数转换为时间字符串
	minutesToTime: function(totalMinutes) {
	    const hours = Math.floor(totalMinutes / 60);
	    const minutes = totalMinutes % 60;
	    return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
	},
	
	// 辅助函数：给时间添加指定分钟数
	addMinutes: function(timeStr, minutesToAdd) {
	    const totalMinutes = item.timeToMinutes(timeStr) + minutesToAdd;
	    return item.minutesToTime(totalMinutes);
	},
};



export default item;